/* libfake437 - a library for the rendering of code page 437 `graphics'
 * Copyright (C) 2008, 2009, 2010 Jack Kelly <endgame.dos@gmail.com>
 *
 * This library is free software: you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation, either version 3 of
 * the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "config.h"
#include <string>
#include <SDL.h>
#include "fake437.h"
#include "fake437/surface.hpp"

namespace fake437 {
  Surface::Surface(SDL_Surface* surface, const F437Font* font):
    surface(f437_surface_new(surface, font)) {}

  Surface::~Surface(void) {
    f437_surface_free(this->surface);
  }

  void Surface::put_char(int left, int top, int ch,
                         const SDL_Color& fg, const SDL_Color& bg) {
    f437_surface_put_char(this->surface, left, top, ch, &fg, &bg);
  }

  void Surface::put_char(int left, int top, int ch,
                         F437Color fg, F437Color bg) {
    f437_surface_put_char(this->surface, left, top, ch,
                          f437_get_color(fg), f437_get_color(bg));
  }

  void Surface::put_rect(int left, int top, int width, int height, int ch,
                         const SDL_Color& fg, const SDL_Color& bg) {
    f437_surface_put_rect(this->surface,
                          left, top, width, height, ch, &fg, &bg);
  }

  void Surface::put_rect(int left, int top, int width, int height, int ch,
                         F437Color fg, F437Color bg) {
    f437_surface_put_rect(this->surface, left, top, width, height, ch,
                          f437_get_color(fg), f437_get_color(bg));
  }

  void Surface::put_string(int left, int top, const char* string,
                           const SDL_Color& fg, const SDL_Color& bg) {
    f437_surface_put_string(this->surface, left, top, string, &fg, &bg);
  }

  void Surface::put_string(int left, int top, const char* string,
                           F437Color fg, F437Color bg) {
    f437_surface_put_string(this->surface, left, top, string,
                            f437_get_color(fg), f437_get_color(bg));
  }

  void Surface::put_string(int left, int top, const std::string& string,
                           const SDL_Color& fg, const SDL_Color& bg) {
    f437_surface_put_string(this->surface, left, top, string.c_str(), &fg, &bg);
  }

  void Surface::put_string(int left, int top, const std::string& string,
                           F437Color fg, F437Color bg) {
    f437_surface_put_string(this->surface, left, top, string.c_str(),
                            f437_get_color(fg), f437_get_color(bg));
  }

  SDL_Surface* Surface::get_surface(void) {
    return this->surface->surface;
  }

  int Surface::get_width(void) const {
    return this->surface->width;
  }

  int Surface::get_height(void) const {
    return this->surface->height;
  }
}
